<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>操作元素的内容</title>
</head>

<body>

    <button>操作内容</button>
    <div>
        <p>文本内容</p>
    </div>
    <!-- <script>
        //获取元素
        var ele = document.querySelector('div')
        var btn = document.querySelector('button')

        //获取元素文本的内容
        console.log(ele.innerText)

        //给按钮绑定点击事件
        btn.onclick = function () {
            //设置div内的文本内容
            ele.innerText = '新内容'
        }
    </script> -->
  
    <script>
        //获取元素
        var ele = document.querySelector('div')
        var btn = document.querySelector('button')

        //获取元素文本的内容
        console.log(ele.innerHTML)

        //给按钮绑定点击事件
        btn.onclick = function () {
            //设置div内的文本内容
            ele.innerHTML = '<span>新内容</span>'
        }
    </script>
</body>

</html>